<?
function _cat_name($cat_id){
    static $cats = array();
    if (isset($cats[$cat_id])) return $cats[$cat_id];
    $cat = Model::factory('article_category')->get($cat_id);
    if (isset($cat['name'])) {
        return $cats[$cat_id] = $cat['name'];
    }
    return '';
}
// 将路径转换为分类名称
function _path_to_name($path) {
    $paths = explode(';', rtrim($path, ';'));
    $names = array();
    foreach ($paths as $id) {
        $names[] = _cat_name($id);
    }
    return implode(' &gt; ', $names);
}
?>
<?=View::factory('admin/common/header')?>
<div id="content">
  <div class="breadcrumb">
    <a href="<?=URL::site('admin')?>">管理首页</a>
    &raquo; 文章列表
  </div>
  <?=View::factory('admin/common/message')?>
  <div class="box">
    <div class="heading">
      <h1><img src="<?=URL::site()?>images/admin/layout.png" alt="" /> 文章列表</h1>
      <div class="buttons">
        <input type="button" onclick="location='<?=URL::site('admin/article/add')?>'" class="btn45" value="添加" />
      </div>
    </div>
    <div class="content">
      <form method="get" name="article_search">
        <fieldset>
          <legend>文章搜索</legend>
          <div>
            分类：<span class="cats_select"><img src="<?=URL::site()?>images/admin/ajax-loading.gif" align="absbottom" /> <font color="gray">数据加载中…</font></span> &nbsp;
            关键字：<input type="text" name="keyword" value="<?=$keyword?>" size="30" /> &nbsp;
            <input type="submit" value="搜索" class="btn45" />
          </div>
        </fieldset>
      </form>
    <table class="list">
      <thead>
        <tr>
          <td class="center autosort" name="art.article_id" width="40">ID</td>
          <td class="left autosort" name="cat.sort_order">所属分类</td>
          <td class="left autosort" name="art.title">标题</td>
          <td class="left autosort" name="art.author">发布者</td>
          <td class="left autosort" name="art.update_time" width="120">更新时间</td>
          <td class="left autosort" name="art.sort_order" width="60">排序</td>
          <td class="left autosort" name="art.clicks" width="60">点击数</td>
          <td class="left autosort" name="art.is_show" width="60">显示</td>
          <td class="right" width="100">操作</td>
        </tr>
      </thead>
      <tbody>
        <? foreach ($pagination as $article) { ?>
        <tr>
          <td class="center"><?=$article['article_id']?></td>
          <td class="left"><?=_path_to_name($article['cat_path'])?></td>
          <td class="left"><?=Str::highlight($article['title'], $keyword)?></td>
          <td class="left"><?=$article['nickname']?></td>
          <td class="left"><?=$article['update_time']?date('Y-m-d H:i', $article['update_time']):'&nbsp;'?></td>
          <td class="left"><?=$article['sort_order']?></td>
          <td class="left"><?=$article['clicks']?></td>
          <td class="left"><img src="<?=URL::site()?>images/admin/<?=$article['is_show']?'yes':'no'?>.gif" /></td>
          <td class="right">
            [ <a href="<?=URL::redirect('admin/article/edit/'.$article['article_id'])?>">编辑</a> ]
            [ <a href="javascript: $.ajax_get({url:'<?=URL::site('admin/article/del/'.$article['article_id'])?>'}); void(0);" class="delete">删除</a> ]
          </td>
        </tr>
        <? } ?>
      </tbody>
    </table>
    <?=$pagination?>
    </div>
  </div>
</div>
<?=View::factory('admin/common/footer')?>
<?=HTML::script('admin/article_category/js')?>
<script type="text/javascript">
$().ready(function(){
    $('.cats_select').html(category_select_reverse(<?=$cat_id?>, 'cat_id', function(obj, cat){
        $('form[name=article_search]').submit();
    }));
    $('#article').addClass('selected');
});
</script>